<?php
/**
 * 公用Model基类
 */
class BaseModel extends RelationModel{
	
	/**
	 * 获取账号ID
	 * @return mixed
	 */
	public function getAccountId(){
		return session('accountId');
	}

	public function getMeetingId() {
		$meetingId = M('Meeting')->where(array('account_id' => session('accountId')))->getField('meeting_id');
		if($meetingId) {
			return $meetingId;
		} else {
			return 0;
		}
	}
	
	/**
	 * 获取公众号ID
	 * @return mixed
	 */
	public function getWechatId(){
		return session('wechatId');
	}
	
	/**
	 * 获取商城ID
	 * @return mixed
	 */
	public function getStoreId(){
		return session('storeId');
	}
	
	/**
	 * 获取充电保ID
	 * @return mixed
	 */
	public function getChargingId(){
		return session('chargingId');
	}

	/**
	 * 获取代理商充电保ID
	 * @return mixed
	 */
	public function getChargingproxId(){
		return session('chargingProxId');
	}
	
	/**
	 * 获取智能洗衣ID
	 * @return mixed
	 */
	public function getLaundryId(){
		return session('laundryId');
	}


	/**
	 * 获取浙铁智能洗衣ID
	 * @return mixed
	 */
	public function getLaundrynewId(){
		return session('laundrynewId');
	}
	
	/**
	 * 获取论坛ID
	 * @return mixed
	 */
	public function getForumId(){
		return session('forumId');
	}
	
	/**
	 * 获取寻物平台ID
	 * @return mixed
	 */
	public function getLostId(){
		return session('lostId');
	}
	
	/**
	 * 获取用户ID
	 * @return mixed
	 */
	public function getUserId(){
		return session('userId');
	}
	
	
	/**
	 * 获取报修ID
	 * @return mixed
	 */
	public function getRepairId(){
		return session('repairId');
	}
	
	/**
	 * 通过主键获取数据
	 * @param string $pk
	 * @param string $field
	 * @return array
	 */
	public function getByPk($pk, $field){
		if($pk){
			$condition[$this->getPk()] = $pk;
			$result = $this->where($condition)->field($field)->find();
		}
		return $result;
	}
	
	/**
	 * 通过条件获取一条数据
	 * @param array $condition
	 * @param string $field
	 * @param string $order
	 * @param string $group
	 * @param integer $limit
	 * @return array
	 */
	public function getInfo($condition, $field, $order , $group , $limit){
		if($condition){
			$result = $this->where($condition)->field($field)->order($order)->group($group)->limit($limit)->find();
		}
		return $result;
	}
	
	/**
	 * 通过条件获取多条数据
	 * @param array $condition
	 * @param string $field
	 * @param string $order
	 * @param string $group
	 * @param integer $limit
	 * @return array
	 */
	public function getList($condition, $field, $order , $group , $limit){
		if($condition){
			$result = $this->where($condition)->field($field)->order($order)->group($group)->limit($limit)->select();
		}
		return $result;
	}
	
	/**
	 * 通过条件统计数量
	 * @param array $condition
	 * @return string
	 */
	public function getCount($condition){
		if($condition){
			$result = $this->where($condition)->count();
		}
		return $result;
	}
	
	/**
	 * 通过条件求和
	 * @param array $condition
	 * @param string $field
	 * @return string
	 */
	public function getSum($condition, $field){
		if($condition && $field){
			$result = $this->where($condition)->sum($field);
		}
		return $result;
	}
	
	/**
	 * 通过条件查询字段
	 * @param array $condition
	 * @param string $field
	 * @param string $isGetArray
	 * @return string
	 */
	public function getFieldByCondition($condition, $field, $isGetArray = false){
        $result = null;
		if($field){
			$result = $this->where($condition)->getField($field, $isGetArray);
		}
		return $result;
	}
}